package com.gitee.liuzhi.demo.juc.threadpoolexecutor.factory;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 线程工厂类
 *
 * @Author liuzhi
 * @Date 2023/9/6 20:39
 * @Version 1.0
 * @Description
 */
public class MyThreadFactory implements ThreadFactory {

    private static final AtomicInteger ATOMIC_INTEGER = new AtomicInteger(0);

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName("thread-name-" + ATOMIC_INTEGER.incrementAndGet());
        return thread;
    }

}
